#! /usr/bin/env python3

import argparse

from plenum.common.config_util import getConfig
from plenum.common.keygen_utils import init_bls_keys
from plenum.common.script_helper import buildKeepDirIfNotExists

config = getConfig()


def parse_args():
    parser = argparse.ArgumentParser(
        description="Generate BLS keys for a node "
                    "by taking the node's name and a seed")

    parser.add_argument('--name', required=True, help='node name')
    parser.add_argument('--seed', required=False, type=str,
                        help='seeds for keypair')

    args = parser.parse_args()

    return args.name, args.seed


def generate_and_store_bls_keys(node_name, seed):
    try:
        init_bls_keys(keys_dir=config.baseDir, node_name=node_name, seed=seed)
    except Exception as ex:
        print(ex)
        exit()


if __name__ == "__main__":
    buildKeepDirIfNotExists(config.baseDir)
    node_name, seed = parse_args()
    init_bls_keys(config.baseDir, node_name, seed)
